﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace DanhMuc
{
    class LuongInfo
    {
        private string _MucLuongID;

        public string MucLuongID
        {
            get { return _MucLuongID; }
            set { _MucLuongID = value; }
        }

        private float _Luong;

        public float Luong
        {
            get { return _Luong; }
            set { _Luong = value; }
        }

        private float _HeSo;

        public float HeSo
        {
            get { return _HeSo; }
            set { _HeSo = value; }
        }

        private bool _Active;

        public bool Active
        {
            get { return _Active; }
            set { _Active = value; }
        }
    }

    class LuongCtr
    {
        string strCnn = DBClass_FANIT82.GetConnectString();

        public void Insert(LuongInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@MucLuongID", Item.MucLuongID),
                new SqlParameter("@Luong", Item.Luong == null ? (object)DBNull.Value:Item.Luong),
                new SqlParameter("@HeSo", Item.HeSo == null ? (object)DBNull.Value:Item.HeSo),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_Luong_Insert", Para);
        }

        public void Update(LuongInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@MucLuongID", Item.MucLuongID),
                new SqlParameter("@Luong", Item.Luong == null ? (object)DBNull.Value:Item.Luong),
                new SqlParameter("@HeSo", Item.HeSo == null ? (object)DBNull.Value:Item.HeSo),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_Luong_Update", Para);
        }

        public void Delete(string strMucLuongID)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@MucLuongID", strMucLuongID),
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_Luong_Delete", Para);
        }

        public DataTable GetList()
        {
            DataSet Ds = SqlHelper.ExecuteDataset(strCnn, CommandType.StoredProcedure, "D_Luong_GetList");
            return Ds.Tables[0];
        }

        public LuongInfo GetByID(string strMucLuongID)
        {
            SqlDataReader dtr = SqlHelper.ExecuteReader(strCnn, CommandType.StoredProcedure, "D_Luong_Get", new SqlParameter("MucLuongID", strMucLuongID));
            LuongInfo ObjLuong = null;
            while (dtr.Read())
            {
                ObjLuong = new LuongInfo();
                ObjLuong.MucLuongID = dtr["MucLuongID"].ToString();
                ObjLuong.Luong = (float)dtr["Luong"];
                ObjLuong.HeSo = (float)dtr["HeSo"];
                ObjLuong.Active = (bool)dtr["Active"];
            }
            return ObjLuong;
        }
    }
}
